<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  * {
    color: deeppink;
  }
</style>

<body>
  <script>
    // 能取到0但是取不到1的随机小数
    console.log("能取到0但是取不到1的随机小数");
    console.log(Math.random());

    // 生成0-10之间的随机整数
    console.log("10之间的随机整数");
    console.log(Math.floor(Math.random() * (10 + 1)));

    console.log("随机抽取数组中的值");
    let arr = ["red", "yellow", "green", "white", "black", "purple", "pink", "blue", "skyblue", "deeppink"];
    // console.log(arr[Math.floor(Math.random() * 10)]);
    let random = Math.floor(Math.random() * arr.length);
    console.log(arr[random]);

    console.log("生成5-10之间的随机数");
    console.log(Math.floor(Math.random() * (5 + 1) + 5));
    console.log("生成N-M之间的随机数：Math.floor(Math.random() * (M-N +1) + N)");

    function getRandom(N, M) {
      return Math.floor(Math.random() * (M - N + 1) + N)
    }
    console.log(getRandom(10, 100));
  </script>

</body>

</html>